﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace OntologyWPFSilverlight.Widget
{
    public class MediaViewer : Canvas
    {
        
        TextBlock label = null;
        MediaElement myMedia = null;
        System.Windows.Controls.Slider sliVolume = null;
        System.Windows.Controls.Slider sliSpeed = null;
        System.Windows.Controls.Slider sliSeek = null;
        
        public MediaViewer()
        {
            Build();
        }

        private void Build()
        {
            StackPanel stackPanel = new StackPanel();
            myMedia = new MediaElement();
            label = new TextBlock();

            StackPanel stackPanel2 = new StackPanel();
            stackPanel2.Orientation = Orientation.Horizontal;
            
            Image play = new Image();
            play.Source = new BitmapImage(new Uri("/Images/play.png"));
            play.MouseLeftButtonDown += new MouseButtonEventHandler(PlayButton_Click);

            Image pause = new Image();
            pause.Source = new BitmapImage(new Uri("/Images/pause.png"));
            pause.MouseLeftButtonDown += new MouseButtonEventHandler(PauseButton_Click);

            Image stop = new Image();
            stop.Source = new BitmapImage(new Uri("/Images/stop.png"));
            stop.MouseLeftButtonDown += new MouseButtonEventHandler(StopButton_Click);

            TextBlock text = new TextBlock();
            text.Text = "Volume";
            sliVolume = new System.Windows.Controls.Slider();
            sliVolume.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Volume_Changed);


            TextBlock text = new TextBlock();
            text.Text = "Speed";
            sliSpeed = new System.Windows.Controls.Slider();
            sliSpeed.ValueChanged += new RoutedPropertyChangedEventHandler<double>(Speed_Changed);

            stackPanel.Children.Add(label);
            stackPanel.Children.Add(myMedia);
            this.Children.Add(stackPanel);
        }

        //void Speed_Changed(object sender, RoutedPropertyChangedEventArgs<double> e)
        //{
        //    myMedia
        //}

        void Volume_Changed(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            myMedia.Volume = (double)sliVolume.Value;
        }

        void PlayButton_Click(object sender, MouseButtonEventArgs e)
        {
            myMedia.Play();
           
        } 
        
        void StopButton_Click(object sender, MouseButtonEventArgs e)
        {
            myMedia.Stop();
        }

        void PauseButton_Click(object sender, MouseButtonEventArgs e)
        {
            myMedia.Pause();
        }
    }
}
